/*
 * 统计模块医疗资源医疗设备js
 * @author 杨腊梅
 * 2016/1/20
 * 
 */


$('#tcm_medicalEquipment_eCharts').css('height',orange.detailPage.getHeight());
$('#tcm_medicalEquipment_eCharts').css('width',orange.detailPage.getWidth());

$('#tcm_medicalEquipment_grid').datagrid(
		{
			url:"d/device/table",
			queryParams:{
				orgGuid:$("#tcmcpdetail_guid").val()
				},
			singleSelect:true,
			rownumbers:true,
			columns:[[
			         {field:'typeName',title:'设备类型',width:'16%',sortable:true,halign:'center'},
			         {field:'deviceName',title:"设备名",width:'16%',sortable:true,halign:'center'},
			         {field:'brand',title:"品牌",width:'16%',sortable:true,halign:'center'},
			         {field:'indate',title:"引进时间",width:'10%',sortable:true,halign:'center'},
			         {field:'uptime',title:'启用时间',width:'10%',sortable:true,halign:'center'},
			         {field:'usedTime',title:"已用年限",width:'10%',sortable:true,halign:'center'},
			         {field:'durableYears',title:"预计使用年限",width:'10%',sortable:true,halign:'center'},
			         {field:'isRent',title:"是否租用",width:'10%',sortable:true,halign:'center',formatter:function(value){
				          	var value_other = value == null ? "" : value;
				          	value_other = value_other==0?"是":"否";
				        	return '<span title="' + value_other + '">' + value_other + '</span>';
				        }},
			         ]],
			pagination:true,
			sortable:true,
			sortName: 'tcm_name',
			sortOrder: 'asc'
		}
);

//combobox设备的字典表
var dicData=[{'id':1,'text':'B超'},{'id':2,'text':'生化仪'},{'id':3,'text':'血液分析'},{'id':4,'text':'CT'}
,{'id':5,'text':'面诊仪'},{'id':6,'text':'脉象仪'}];
$("#tcm_dic_Equipment").combobox({
//	url:'/statistics/device',
	data:dicData,   
    valueField:'id',   
    textField:'text',
    panelHeight:'auto',
	width:'150px',
    onLoadSuccess:function(data){
    	$("#tcm_dic_Equipment").combobox('setValue',data[0].id);
    }
});

/*
 * 图表数据初始化
 */
var tcm_myChart = echarts.init($('#tcm_medicalEquipment_eCharts')[0]);
var tcm_initData;
var deviceTotal = [];
var deviceNum = [];
var tcm_xData = [];
$.ajax({
	url:"d/device/chart",
	type:"get",
	data:{
		orgGuid:$("#tcmcpdetail_guid").val(),
		deviceType:"1"},
	success:function(data){
		tcm_initData = JSON.parse(data)
			for(var i=0; i<tcm_initData.length; i++) {
			deviceTotal.push(tcm_initData[i].deviceTotal);
			deviceNum.push(tcm_initData[i].deviceNum);
			tcm_xData.push(tcm_initData[i].period);
		}
		tcm_myChart.setOption(tcm_option);
	}
});

/*
 * 设置图表格式
 */
tcm_option={
		grid:{
			show:false,
			bottom :'15%',
			top:'25%',
			height:'65%',
			width:'80%',
			left:'10%',
			right:'15%'
		},
		tooltip : {
			trigger : 'axis'
		},
		
		legend : {
			top : '5%',
			data : ['设备总量', '该设备数量']
		},
		
		xAxis : [{
			type : 'category',
			boundaryGap : false,
			data : tcm_xData
		}],
		
		yAxis : [{
			type:'value'
		}],
		
		series : [
		  {
			  type : 'line',
			  name : "设备总数",
			  smooth : true,
			  data : deviceTotal
		  },
		  {
			  type : 'line',
			  name : "该设备数量",
			  smooth : true,
			  data : deviceNum
		  }
		],
};

//使用刚指定的配置项和数据显示图表
tcm_myChart.setOption(tcm_option);